<?php
	class SystemTablesColumnsLogsController extends Controller
	{
		public $page_title = LANG_SYSTEM_TABLES_COLUMNS;
		public $layout = 'main';
		public $module = 'administration';
		public $helpers = array ('html', 'htmlx', 'toolbars', 'grids');
		public $name = 'system_tables_columns_logs';
		public $use_logging = false;
						
		/**
		 * Manages the columns logs settings
		 * @param int $system_table_id
		 */
		function Edit($system_table_id = null)
		{
			$this->data['system_table_id'] = $system_table_id;
			$this->data['columns_logs'] = $this->controller_model->ListItems(array("system_table_id" => $system_table_id));

			if (!empty($this->request->post))
			{
				$this->SaveColumnsLogs($this->request->post, $system_table_id);
				$this->Redirect('system_access_logs/edit/');
			}
			else
			{

			}
		}
		
		/**
		 * Saves the data
		 * @param array $data
		 */
		private function SaveColumnsLogs($data)
		{
			$is_logged_list = '0';
			$is_commented_list = '0';
			foreach ($data['column_log'] as $key => $value)
			{
				if($value['is_logged'] == 1) $is_logged_list = $is_logged_list.', '.$key;
				if($value['is_commented'] == 1)	$is_commented_list = $is_commented_list.', '.$key;
			}
			$this->controller_model->Update(array('system_table_id' => $data['system_table_id'], 'is_logged_list' => $is_logged_list, 'is_commented_list' => $is_commented_list), 'sp_system_tables_columns_logs_update_list');
		}
	
		/**
		 * Displays the access logs settings
		 * @param int $system_table_id
		 */
		function View($system_table_id)
		{
			$this->data['system_table_id'] = $system_table_id;
			$this->data['columns_logs'] = $this->controller_model->ListItems(array("system_table_id" => $system_table_id));
		}
	}
?>